<template>
  <div>hello,{{ userInfo.name }}</div>
  <button @click="logout">退出登录</button>
</template>

<script>
import { useStore } from 'vuex'
import { useRouter, useRoute } from 'vue-router'
import { computed } from 'vue'
export default {
  name: 'home',
  setup() {
    const store = useStore()
    const route = useRoute()
    const router = useRouter()
    const userInfo = computed(() => store.getters.userInfo)
    const logout = async () => {
      await store.dispatch('user/logout')
      router.push(`/login?redirect=${route.fullPath}`)
    }
    return {
      userInfo,
      logout
    }
  }
}
</script>

<style scoped lang="scss"></style>
